interface User {
    name: string;
    age?: number;
    readonly id: string;
}


// keyof 返回联合类型 相当于 name age id 都在这里
type keys = keyof User;
let key: keys = "name"

// ---------------------
type User1 = Partial<User>
type customPartial<T> = {
    [P in keyof T]?: T[P]
}
type User2 = customPartial<User>



// ---------------------
type user3 = Required<User>
type CustomRequired<T> = {
    [P in keyof T]-?: T[P]
}
type user4 = CustomRequired<User>



// ---------------------
type user5 = Pick<User, 'age' | 'id'>
type customPick<T, K extends keyof T> = {
    [P in K]: T[P]
}
type user6 = Pick<User, 'age' | 'id'>


// ---------------------
type user7 = Exclude<'id' | 'age' | 'sex', 'id'>
type customExclude<T, U> = T extends U ? never : T
type user8 = customExclude<'id' | 'age' | 'sex', 'id'>


// ---------------------
type user9 = Omit<User, 'age'>
// 1. 先去掉过滤的key
// 2. Pick 剩余的Key
type keyType = keyof any
type customOmit<T, keyType> = Pick<T, Exclude<keyof T, keyType>>
type user10 = Omit<User, 'age' | 'id'>
type user11 = Omit<User, 'age'>



// ---------------------

//record 约束对象的key和value

type Key = "c" | "x" | "k";

type Value = '唱' | '跳' | 'rap' | '篮球'

let obj: Record<Key, Value> = {
    c: '唱',
    x: '跳',
    k: '唱'
}
type CustomRecord<K extends keyof any, T> = {
    [P in K]: T
}
let obj2: CustomRecord<Key, Value> = {
    c: '唱',
    x: '跳',
    k: 'rap'
}

const fn = () => [1, 2, 3, 'sad'];

type num = ReturnType<typeof fn>
type CustomFn<F extends Function> = F extends (...args: any[]) => infer Res ? Res : never;
type num2 = CustomFn<typeof fn>
type FnType = typeof fn
